package com.lightjet.macross.base.auth;

import com.lightjet.macross.common.util.JwtUtil;
import com.lightjet.macross.common.util.MD5Util;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.DigestUtils;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.UUID;

@SpringBootTest
public class TokenTester {

    @Test
    public void TestSign()
    {
        HashMap<String,String > map = new HashMap<>();
        map.put("uid","0729");
        map.put("pwd","32-94-A7-6B-7D-06-54-AA-B2-1E-D8-D6-04-5B-D7-BD");
        map.put("cid","dr802-ui");
        map.put("cs","802sastcasc!");
/*        map.put("uid","0000");
        map.put("pwd","802sastcasc!");
        map.put("cid","palms802-ui");
        map.put("cs","802sastcasc!");*/
        System.out.println(JwtUtil.signWithClaims(300,"802sastcasc!",map));
    }

    @Test
    public void TestVerify()
    {
        String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIyMjMwIiwicHdkIjoicG9oaWdoIiwiZXhwIjoxNTc1MzM1MjE3fQ.iVEGFbelHVYQtU5YCxzgi4f2ya8AvUyeGTCP-ukGEis";
        boolean flag = JwtUtil.verify(token,"802sastcasc!");
        HashMap<String,String> map = JwtUtil.getTokenClaims(token,"uid","pwd");
        System.out.println(map.get("uid")+":"+map.get("pwd"));
    }

    @Test
    public void TestEncoder()
    {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        System.out.println(bCryptPasswordEncoder.encode("test"));
        System.out.println(bCryptPasswordEncoder.matches("test","$2a$10$hFmIqSATGQpurw.Oq0i5QeGWZZib1GaZJAs9uviy9yOl.zaKuvdwK"));
    }

    @Test
    public void TestMD5()
    {
/*        System.out.println(MD5Util.GetMD5Code("test"));
        System.out.println(MD5Util.GetMD5Code("test"));*/
/*        String test = null;
        try {
            test = DigestUtils.md5DigestAsHex("test".getBytes("UTF-16le"));
            System.out.println(test);
            System.out.println(DigestUtils.md5DigestAsHex(test.getBytes("UTF-16le")));
        } catch (UnsupportedEncodingException e) {
            test = "";
            e.printStackTrace();
        }*/
        String a = UUID.randomUUID().toString();
        String t = MD5Util.Encode("test", a);
        System.out.println(t);
        t = MD5Util.Encode("test", a);
        System.out.println(t);

    }
}
